package com.ruoyi.system.init;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.redis.RedisUtil;
import com.ruoyi.common.utils.ProjectConstant;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.PriceSetting;
import com.ruoyi.system.mapper.PriceSettingMapper;

/**
 *	系统初始化数据
 * @author DEREK
 */
@Component
public class SystemInitData {

	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private PriceSettingMapper priceSettingMapper;
	
	@PostConstruct
	public void whiteApiInit() {
		// 设置需要检验token的接口地址
		System.out.println("-----------初始化任务start-------");
		// 用户
//		ProjectConstant.TOKEN_URL_LIST.add("/api/v1/system/qryAliAK");
		// 系统接口
		
		
		// 初始化基础配置
		PriceSetting set = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>().eq(PriceSetting::getPriceType, "解锁微信次数")
				.select(PriceSetting::getId,PriceSetting::getPriceName).last("limit 1"));
		if(null != set && StringUtils.isNotEmpty(set.getPriceName()) && Integer.valueOf(set.getPriceName()) > 0) {
			redisUtil.set(ProjectConstant.platformConstant.UNLOCKWECHATCOUNT, Integer.valueOf(set.getPriceName()));
		}
		set = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>().eq(PriceSetting::getPriceType, "解锁聊天次数")
				.select(PriceSetting::getId,PriceSetting::getPriceName).last("limit 1"));
		if(null != set && StringUtils.isNotEmpty(set.getPriceName()) && Integer.valueOf(set.getPriceName()) > 0) {
			redisUtil.set(ProjectConstant.platformConstant.UNLOCKCHATCOUNT, Integer.valueOf(set.getPriceName()));
		}
		set = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>().eq(PriceSetting::getPriceType, "解锁微信")
				.select(PriceSetting::getId,PriceSetting::getCurrentPrice).last("limit 1"));
		if(null != set && null != set.getCurrentPrice()) {
			redisUtil.set(ProjectConstant.platformConstant.UNLOCKWECHATPRICE, set.getCurrentPrice());
		}
		set = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>().eq(PriceSetting::getPriceType, "解锁聊天")
				.select(PriceSetting::getId,PriceSetting::getCurrentPrice).last("limit 1"));
		if(null != set && null != set.getCurrentPrice()) {
			redisUtil.set(ProjectConstant.platformConstant.UNLOCKCHATPRICE, set.getCurrentPrice());
		}
		
		// 初始化默认头像
		ProjectConstant.maleList.add("https://accost.oss-cn-shenzhen.aliyuncs.com/defaultHeadPic/m1.png");
		ProjectConstant.maleList.add("https://accost.oss-cn-shenzhen.aliyuncs.com/defaultHeadPic/m2.png");
		ProjectConstant.femaleList.add("https://accost.oss-cn-shenzhen.aliyuncs.com/defaultHeadPic/n1.jpg");
		ProjectConstant.femaleList.add("https://accost.oss-cn-shenzhen.aliyuncs.com/defaultHeadPic/n2.png");
		System.out.println("-----------初始化任务end-------");
	}
}
